package cst.neu.yuejian_31.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.List;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.activity.AttentionActivity;
import cst.neu.yuejian_31.adapter.CollectClubAdapter;
import cst.neu.yuejian_31.bean.CollectClubBean;
import cst.neu.yuejian_31.iface.CollectClubListener;
import cst.neu.yuejian_31.model.CollectClubModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class ClubAttentionFragment extends BaseFragment implements  CollectClubListener {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private View view=null;
    private List<CollectClubBean> list=null;
    private String userId;
    private Context context;
    private CollectClubAdapter collectClubAdapter;
    private ImageView docollect;
    private String clubId;



    public ClubAttentionFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_club__attention, container, false);
        initDate();
        initView();
        return view;
    }


    private void initDate() {
        Intent intent=getActivity().getIntent();
        clubId=intent.getStringExtra("club_id");


        userId=((AttentionActivity)getActivity()).getUserId();
        CollectClubModel model=new CollectClubModel();
        model.getCollectClub(userId,this);
    }

    private void initView() {
        context=this.getActivity();
        recyclerView= (RecyclerView) view.findViewById(R.id.recyclerView_clubcollect);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        collectClubAdapter=new CollectClubAdapter(context);
        collectClubAdapter.setList(list);
        recyclerView.setAdapter(collectClubAdapter);
// 设置Item之间间隔样式
        recyclerView .addItemDecoration(new DividerItemDecoration(context,LinearLayoutManager.VERTICAL));
    }

    @Override
    public void onSuccess(List<CollectClubBean> collectClubBean) {
        list=collectClubBean;
        collectClubAdapter.setList(list);
    }


    @Override
    public void onFail(String msg) {
        Toast.makeText(context,msg, Toast.LENGTH_SHORT).show();
    }



}
